Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Query Function As Query_string Function #143

Merged
merged 1 commit into from
Nov 2, 2022

Conversation

GabeFernandez310
Copy link

@GabeFernandez310 GabeFernandez310 commented Oct 26, 2022

Description

Added query function to SQL plugin. Achieved by routing function calls from the SQL plugin to the query_string function which currently exists in OpenSearch.

Currently blocked by opensearch-project#839. PR to upstream will be made once PR opensearch-project#839 is merged.

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@codecov
Copy link

codecov bot commented Oct 26, 2022

Codecov Report

Merging #143 (52ea1e5) into integ-add-query-function (89b3e1a) will increase coverage by 0.28%.
The diff coverage is 100.00%.

@@                      Coverage Diff                       @@
##             integ-add-query-function     #143      +/-   ##
==============================================================
+ Coverage                       94.95%   95.23%   +0.28%     
- Complexity                       3190     3395     +205     
==============================================================
  Files                             316      330      +14     
  Lines                            8646     9302     +656     
  Branches                          637      691      +54     
==============================================================
+ Hits                             8210     8859     +649     
- Misses                            382      386       +4     
- Partials                           54       57       +3     
Flag Coverage Δ
query-workbench 62.76% <ø> (ø)
sql-engine 97.70% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...arch/storage/script/filter/FilterQueryBuilder.java 100.00% <ø> (ø)
...c/main/java/org/opensearch/sql/expression/DSL.java 100.00% <100.00%> (ø)
...h/sql/expression/function/OpenSearchFunctions.java 100.00% <100.00%> (ø)
...e/script/filter/lucene/relevance/NoFieldQuery.java 100.00% <100.00%> (ø)
...age/script/filter/lucene/relevance/QueryQuery.java 100.00% <100.00%> (ø)
...script/filter/lucene/relevance/RelevanceQuery.java 100.00% <100.00%> (ø)
...pensearch/sql/sql/parser/AstExpressionBuilder.java 100.00% <100.00%> (ø)
...ain/java/org/opensearch/sql/analysis/Analyzer.java 100.00% <0.00%> (ø)
...java/org/opensearch/sql/ppl/parser/AstBuilder.java 100.00% <0.00%> (ø)
...java/org/opensearch/sql/storage/StorageEngine.java 100.00% <0.00%> (ø)
... and 25 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link

@acarbonetto acarbonetto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job guys! Thanks for the work. Just a couple of comments

docs/user/dql/functions.rst Outdated Show resolved Hide resolved
@@ -38,7 +38,7 @@ public void queryTest() throws IOException {
"select address from %s where query('address:880 Holmes Lane') limit 3",
TestsConstants.TEST_INDEX_ACCOUNT));
Assert.assertThat(result,
containsString("query_string\":{\"query\":\"address:880 Holmes Lane"));
containsString("query_string\\\":{\\\"query\\\":\\\"address:880 Holmes Lane"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't working?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were some issues with escaped characters causing it to fail.

docs/user/dql/functions.rst Outdated Show resolved Hide resolved
@Test
public void all_fields_test() throws IOException {
String query = "SELECT * FROM "
+ TEST_INDEX_BEER + " WHERE query('*:taste')";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the wildcard syntax doesn't work? Or does it work with just *?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too... I thought we determined that they didn't work when we had our 1:1. I played around with it trying different combinations...

The following all seem to work when passed in as the query for query_string:

"* : taste"
"* : ?aste"
"Tags : *aste"
"Tags : Ta?te"
"Tags : Ta*te"

I tried these according to this documentation for Lucene, but it doesn't seem to follow it exactly since it also allows * and ? to be the first character of a search. Should we add tests for all of these cases as well? I can't find a specific Doc to reference for what should/shouldn't be supported in the query so I'm not really sure what other behaviour we should be testing for that we might be missing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Unit Tests in f2d77c6

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was more asking about the field name (* or Tags). It seems like those two cases are fine, but T?g* is not?

Honestly, the checks are handled by OpenSearch not us... so what additional tests are going to do is test another system. We can consider covering some of the general cases, but we do not need to be exhaustive here.

@Yury-Fridlyand
Copy link

Hint:
Add Signed-off-by: ... line manually if you commit suggestion via GH to avoid DCO failure.

@@ -81,4 +102,5 @@ public QueryBuilder build(FunctionExpression func) {
protected interface QueryBuilderStep<T extends QueryBuilder> extends
BiFunction<T, ExprValue, T> {
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting change not needed, and really should only be included in a review when appropriate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7add05f

@@ -523,6 +523,7 @@ public void relevanceSimple_query_string() {
+ "analyzer='keyword', operator='AND')"));
}


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7add05f

String.format("Parameter '%s' can only be specified once.", k));
}
});
.forEach((k, v) -> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting change not needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduced by accident when I was trying to fix checkstyle issues. Fixed in 7add05f

queryBuildActions
.get(argNormalized)))
.apply(queryBuilder, arg.getValue().valueOf(null));
queryBuildActions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting change not needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduced by accident when I was trying to fix checkstyle issues. Fixed in 7add05f

Copy link

@forestmvey forestmvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good other than some unnecessary formatting changes.

@Test
public void all_fields_test() throws IOException {
String query = "SELECT * FROM "
+ TEST_INDEX_BEER + " WHERE query('*:taste')";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was more asking about the field name (* or Tags). It seems like those two cases are fine, but T?g* is not?

Honestly, the checks are handled by OpenSearch not us... so what additional tests are going to do is test another system. We can consider covering some of the general cases, but we do not need to be exhaustive here.

@@ -2963,7 +2963,7 @@ Description

``query_string([field_expression+], query_expression[, option=<option_value>]*)``

The query_string function maps to the query_string query used in search engine, to return the documents that match a provided text, number, date or boolean value with a given field or fields.
The query_string function maps to the query_string query used in search engine (also used by `query`_), to return the documents that match a provided text, number, date or boolean value with a given field or fields.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove, this is confusing and covered below

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7add05f


``query("query_expression" [, option=<option_value>]*)``

This is an alternative syntax to the `query_string`_ function. The query function maps to the query_string query used in search engine, to return the documents that match a provided text, number, date or boolean value with a given field or fields.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is an alternative syntax to the `query_string`_ function. The query function maps to the query_string query used in search engine, to return the documents that match a provided text, number, date or boolean value with a given field or fields.
The `query` function is an alternative syntax to the `query_string` function. It maps to the query_string query used in search engine, to return the documents that match a provided text, number, date or boolean value with a given query expression.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to remove the links entirely? They were originally added to address this comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can apply the change and restore the link.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the language to match the suggestion, but kept the link to query_string. Please let me know if you are ok with this. Done in 7add05f

void query_expression() {
assertAnalyzeEqual(
dsl.query(
dsl.namedArgument("query", DSL.literal("query_value"))),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: change "query_value" to "sample query" or "field:query" or something similar.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ef2f4c9

@GabeFernandez310 GabeFernandez310 changed the base branch from integ-improve-error-reporting to integ-add-query-function November 1, 2022 22:54
@GabeFernandez310 GabeFernandez310 merged commit 2776fdd into integ-add-query-function Nov 2, 2022
@GabeFernandez310 GabeFernandez310 deleted the dev-add-query-function branch December 1, 2022 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants